import cv2
cap = cv2.VideoCapture(0) # 打开默认摄像头
if cap.isOpened():
    print("成功打开摄像头")
else :
    print("无法打开摄像头")
    exit()

while True:
    ret , frame = cap.read()
    cv2.imshow("frame",frame)
    if cv2.waitKey(1) & 0xff == 27:
        break
cv2.waitKey(0)
cap.release()
cv2.destroyAllWindows()